//
//  XYPopMenuView.m
//  OC_weibo
//
//  Created by 李旭阳 on 16/1/9.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "XYPopMenuView.h"


@interface XYPopMenuView()

@property(nonatomic,strong)UIImageView *bgView;

@end


@implementation XYPopMenuView

-(instancetype)initWithCustomView:(UIView *)customView{
    self = [super init];
    if (self) {
        self.size = [UIScreen mainScreen].bounds.size;
        [self addTarget:self action:@selector(hide:) forControlEvents:UIControlEventTouchUpInside];
        
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.image = [UIImage imageNamed:@"popover_background"];
        imageView.userInteractionEnabled = YES;
        imageView.size = CGSizeMake(customView.width + 10, customView.height + 20);
        
        customView.x = 5;
        customView.y = 12;
        
        [imageView addSubview:customView];
        
        [self addSubview:imageView];
        
        self.bgView = imageView;
        
    }
    return self;
}

-(void)showWithView:(UIView *)targetView{
    
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    CGRect rect = [targetView convertRect:targetView.bounds toView:window];
    self.bgView.centerX = CGRectGetMidX(rect);
    self.bgView.y = CGRectGetMaxY(rect);
    
    [window addSubview: self];
}

#pragma mark 监听方法
-(void)hide:(UIButton *)button{
    [self removeFromSuperview];
}
@end
